package thread;

import java.math.BigDecimal;

public class WaitNotifyTest {

    public static void main(String[] args) {
        ThreadB threadB = new ThreadB();
        threadB.start();

        synchronized (threadB) {
            try {
                System.out.println("Waiting for b to complete...");
                // 调用wait 后自动释放锁
                threadB.wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("Total is:" + threadB.total);
        }
    }

}

class ThreadB extends Thread {
    int total;

    @Override
    public void run() {
        synchronized (this) { synchronized (this) {
                for (int i = 0; i < 100; i++) {
                    total += 1;
                    System.out.println("_total:" + total);
                }
                notify();
            }
        }
    }
}
